package com.an.vhr.controller;

import com.an.vhr.bean.RespBean;
import com.an.vhr.config.VerificationCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * @Author: an1089
 **/
@RestController
public class LoginController {
    @GetMapping("/login")
    public RespBean login(){
        return RespBean.error("请先登录");
    }

    @GetMapping("/verifyCode")
    public void verifyCode(HttpSession session, HttpServletRequest req, HttpServletResponse response){
        VerificationCode code = new VerificationCode();
        BufferedImage image = code.getImage();
        String text = code.getText();
        if(session!=null){
            session.setAttribute("verify_code",text);
            System.out.println("验证码:"+text);
        }
        try {
            VerificationCode.output(image,response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
